// sd_liferuning/pages/constmer/balance-recharge/index.js
var api = require("../../../../api.js"),app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: 0,
    balance: 50
  },    
  changeInputData: function (e) {
    let that = this;
    let inputName = e.currentTarget.dataset.name;
    let inputVlaue = e.detail.value;
    if (inputName == "money") {
      that.setData({
        money: inputVlaue
      });
    }
  },
  sendRequest: function(){
    let _this=this;
    let _money = _this.data.money;
    let _balance = _this.data.balance;
    
    if (_money > _balance || _money == "") {
      wx.showToast({
        title: '请正确填写金额',
        icon: 'none'
      })
      return false;
    }else{
      wx.request({
        url: api.default.BusinessPay,
        data:{
          uid:wx.getStorageSync('uid'),
          price: _money,
          type:2
        },
        method:'post',
        success:function(res){
          if (res.data.error==0){
            wx.showToast({
              title: '提现成功！',
            })
            setTimeout(() => {
              wx.navigateTo({
                url: '/service/pages/service/balance-management/index',
              })
            }, 2000)         
          }else{
            wx.showToast({
              title: '企业未开通此资质',
            })
          }
          
        }
      })
    }
  
    // TODO 执行请求
  
  },
    onLoad:function(){
      var that = this
      that.setData({
        icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
      })
    }
})